# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        # if not head:
        #     return None
        head, now_note = ListNode(None), head
        wei = head
        while now_note:
            now_val = now_note.val
            if now_note.next and now_note.next.val == now_val:
                while now_note.next and now_note.next.val == now_val:
                    now_note = now_note.next
                if not now_note.next:
                    wei, wei.next = None, None
                    break
            else:
                wei.next, wei = now_note, now_note
            now_note = now_note.next
        if wei:
            wei.next = None
        return head.next
